package cq.zhcqk.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;

/**
 * Created by zhangle on 2017/5/29.
 */
public class PhoneHelper {

    public static String getPhoneNo(Context context){
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String deviceid = tm.getDeviceId();
        String tel = tm.getLine1Number();//手机号码
        if(tel == null){
            return "";
        }
        return tel;
    }

    /**
     * 获取手机型号
     *
     * @return  手机型号
     */
    public static String getSystemModel() {
        return android.os.Build.MODEL;
    }

    /**
     * 获取本地版本号
     * @return
     */
    public static int getLocal(Context context) {
        int mLocalVersion = 0;
        PackageInfo packageInfo;
        try {
            packageInfo = context.getApplicationContext()
                    .getPackageManager().getPackageInfo(context.getPackageName(), 0);
            mLocalVersion = packageInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }
        return mLocalVersion;
    }
}
